package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.vo.category.CategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	@GetMapping(value = "/getBaseCategoryList")
	@Operation(summary = "查询全平台的分类信息")
	public Result getBaseCategoryList() {
		List<CategoryVo> result = baseCategoryService.getBaseCategoryList();
		return Result.ok(result);
	}


	@GetMapping("/findAttribute/{c1Id}")
	@Operation(summary = "根据一级分类id查询该分类下的标签信息")
	@Parameter(name = "c1Id", description = "一级分类id", required = true)
	// 标签=属性+属性值
	public Result findAttributeAndValue(@PathVariable(value = "c1Id") Long c1Id) {
		List<BaseAttribute> baseAttributes = baseCategoryService.findAttributeAndValue(c1Id);
		return Result.ok(baseAttributes);
	}

	@GetMapping("/findTopBaseCategory3/{c1Id}")
	@Operation(summary = "根据一级分类id获取7个置顶的三级分类对象")
	// 标签=属性+属性值
	public Result findTopBaseCategory3(@PathVariable(value = "c1Id") Long c1Id) {
		List<BaseCategory3> c1Id7TopBaseCategory3List = baseCategoryService.getC1Id7TopBaseCategory3List(c1Id);
		return Result.ok(c1Id7TopBaseCategory3List);
	}


	//http://localhost:8500/api/album/category/getBaseCategoryList/2
	@GetMapping("/getBaseCategoryList/{albumId}")
	@Operation(summary = "根据一级分类id查询所有的二级分类以及三级分类")
	public Result getAllBaseCategoryList(@PathVariable(value = "albumId") Long albumId){
		CategoryVo categoryVo = baseCategoryService.getAllBaseCategoryList(albumId);
		return Result.ok(categoryVo);
	}

}

